package cn.com.lyj6851.common.bean;

import cn.com.lyj6851.modules.user.domain.YdyUser;

import java.util.HashMap;
import java.util.Map;

/**
 * 全局user
 */
public class LocalUser {
    // 初始化一个全局线程变量
    private static final ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal<>();

    public static void set(YdyUser user, Integer scope) {
        Map<String, Object> map = new HashMap<>();
        map.put("user", user);
        map.put("scope", scope);
        LocalUser.threadLocal.set(map);
    }

    public static void clear() {
        LocalUser.threadLocal.remove();
    }

    public static YdyUser getUser() {
        Map<String, Object> map = LocalUser.threadLocal.get();
        return (YdyUser)map.get("user");
    }

    public static Integer getScope() {
        Map<String, Object> map = LocalUser.threadLocal.get();
        return (Integer)map.get("scope");
    }
}
